<?php

namespace Admin\Models\res;

use Admin\Models\BaseModel;
class XhresResourcepack extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iRPId;

    /**
     *
     * @var string
     */
    public $sRPVersion;

    /**
     *
     * @var string
     */
    public $sRPDownUrl;

    /**
     *
     * @var string
     */
    public $sRPName;

    /**
     *
     * @var integer
     */
    public $iSortCode;

    /**
     *
     * @var string
     */
    public $sSuffixName;

    /**
     *
     * @var string
     */
    public $mRPIntro;

    /**
     *
     * @var integer
     */
    public $iRPSize;

    /**
     *
     * @var string
     */
    public $sRPMd5;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var string
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var string
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHRes_ResourcePack");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHRes_ResourcePack';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhresResourcepack[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhresResourcepack
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 根据数据创建model并返回
     *
     * @param array $data
     * @return XhresResourcepack
     *
     * create by ck 20161218
     */
    public static function createRecord($data = array())
    {
        $obj = $data['iRPId'] ? self::findFirst($data['iRPId']) : new self;
        $obj or $obj = new self;
        $obj->assign($data);
        $obj->bDelete = 0;
        return $obj;
    }

    /**
     * 根据id删除相应记录
     *
     * @param $idArr
     * @return mixed
     *
     * create by ck 20161218
     */
    public static function deleteRecordById($idArr)
    {
        return self::find([
            'conditions' => 'bDelete = 0 and iRPId in ({idArr:array})',
            'bind'       => ['idArr' => $idArr]
        ])->delete();
    }

}
